package com.leo.tool.convert.mapper;

import com.leo.tool.convert.dto.Customer;
import com.leo.tool.convert.dto.CustomerDto;
import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.factory.Mappers;

@Mapper(uses = {OrderItemMapper.class})
public interface CustomerConverter {

    CustomerConverter INSTANCE = Mappers.getMapper(CustomerConverter.class);

    @Mapping(target = "name", source = "customerName")
    @Mapping(target = "orders", source = "orderItems")
    Customer convert(CustomerDto customerDto);

    @InheritInverseConfiguration(name = "convert")
    CustomerDto convert(Customer customer);

    @Mapping(target = "name", source = "customerName")
    @Mapping(target = "orders", source = "orderItems")
    void update(@MappingTarget Customer customer, CustomerDto customerDto);

    Customer clone(Customer customerDto);
}
